﻿using System.Collections.Generic;
using Demo.Api.Entities;
using KmFlow;

namespace Demo.Api.Models
{
    /// <summary>
    ///     事项实例关联的流程图
    /// </summary>
    public class FlowChartProcessNodeAndLineDto
    {
        /// <summary>
        ///     事项实例相关的所有节点
        /// </summary>
        public List<FlowChartProcessNode> Nodes { get; set; }

        /// <summary>
        ///     事项实例相关的所有线
        /// </summary>
        public List<FlowChartProcessLineDto> Lines { get; set; }
    }

    public class FlowChartProcessNode : NodeDo
    {
        public FlowChartProcessNode(NodeDo data, FlowChartProcessDo input)
        {
            Id = data.Id;
            FlowChartId = data.FlowChartId;
            Name = data.Name;
            NodeType = data.NodeType;
            Logic = data.Logic;
            OrClear = data.OrClear;
            SeparateNodeId = data.SeparateNodeId;
            RuleId = data.RuleId;
            PositionX = data.PositionX;
            PositionY = data.PositionY;
            Code = data.Code;
            Remarks = data.Remarks;
            if (input == null)
            {
                Passed = 1;// 未经过
            }
            else
            {
                if (input.OperatingNodeType == (int)OperatingNodeType.Working)
                {
                    Passed = 2;// 正在操作中
                }
                else
                {
                    Passed = 3;// 历史节点
                }

            }

        }

        /// <summary>
        ///     经过的状态
        /// </summary>
        public byte Passed { get; private set; }
    }

    public class FlowChartProcessLineDto : LineDo
    {
        public FlowChartProcessLineDto(LineDo data)
        {
            Id = data.Id;
            Remarks = data.Remarks;
            Name = data.Name;
            TailNodeId = data.TailNodeId;
            FlowChartId = data.FlowChartId;
            HeadNodeId = data.HeadNodeId;
            LineType = data.LineType;
            Code = data.Code;
        }

        public FlowChartProcessLineDto(LineDo data, string nodeName) : this(data)
        {
            NodeName = nodeName;
        }
        /// <summary>
        ///     经过的
        /// </summary>
        public bool Passed { get; set; }
        /// <summary>
        /// 关联节点的名称
        /// </summary>
        public string NodeName { get; set; }
    }
}